//
//  ByCellRedPacketComeIn.m
//  mijifen_ios
//
//  Created by 朱凯 on 2017/11/7.
//  Copyright © 2017年 itboye. All rights reserved.
//

#import "ByCellRedPacketComeIn.h"

@implementation ByCellRedPacketComeIn
{
    UIImageView *_redView1;
    UIImageView *_redView2;
    UIImageView *_redView3;
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        self.selectionStyle = UITableViewCellSeparatorStyleNone;
        self.backgroundColor = [UIColor whiteColor];
        [self setupUI];
    }
    return self;
}
- (void)setupUI {
    
    _redView1 = [self redPacketView];
    _redView2 = [self redPacketView];
    _redView3 = [self redPacketView];
    
    _redView1.tag = 0;
    _redView2.tag = 1;
    _redView3.tag = 2;
    
    [_redView1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@10);
        make.top.equalTo(@0);
        make.width.equalTo(@((SCREEN_WIDTH - 30) / 3));
        make.height.equalTo(_redView1.mas_width).multipliedBy(1.3);
        
        make.bottom.equalTo(self.contentView);
    }];
    [_redView2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.top.equalTo(_redView1);
        make.left.equalTo(_redView1.mas_right).offset(5);
    }];
    [_redView3 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.top.equalTo(_redView2);
        make.left.equalTo(_redView2.mas_right).offset(5);
    }];
}

- (UIImageView *)redPacketView {
    
    // 背景
    UIImageView *redView = [UIImageView new];
    redView.image = [UIImage imageWithColor:[UIColor redColor]];
    [self.contentView addSubview:redView];
    
    // 商家名称
    UILabel *nameLabel = [[UILabel alloc] init];
    nameLabel.text = @"大森林保险";
    nameLabel.font = FONT(12);
    nameLabel.textAlignment = NSTextAlignmentCenter;
    nameLabel.textColor = [UIColor whiteColor];
    [redView addSubview:nameLabel];
    
    // 金额
    UILabel *moneyLabel = [[UILabel alloc] init];
    moneyLabel.font = FONT(20);
    moneyLabel.adjustsFontSizeToFitWidth = true;
    moneyLabel.textAlignment = NSTextAlignmentCenter;
    moneyLabel.backgroundColor = [UIColor yellowColor];
    moneyLabel.textColor = BY_GOLD_COLOR;
    [redView addSubview:moneyLabel];
    moneyLabel.layer.cornerRadius = 30;
    moneyLabel.layer.masksToBounds = true;
    
    NSMutableAttributedString *attr = [[NSMutableAttributedString alloc] initWithString:@"￥999"];
    [attr addAttribute:NSFontAttributeName value:FONT(14) range:NSMakeRange(0, 1)];
    moneyLabel.attributedText = attr;

    // 距离
    UILabel *distanceLabel = [[UILabel alloc] init];
    distanceLabel.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.2];
    distanceLabel.text = @"<300m";
    distanceLabel.font = FONT(12);
    distanceLabel.textAlignment = NSTextAlignmentRight;
    distanceLabel.textColor = [UIColor whiteColor];
    [self.contentView addSubview:distanceLabel];
    
    
    nameLabel.tag = 100;
    moneyLabel.tag = 101;
    distanceLabel.tag = 102;
    
    [nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(@0);
        make.left.equalTo(@10);
        make.right.equalTo(@(-10));
        make.height.equalTo(@40);
    }];
    [moneyLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.height.equalTo(redView.mas_width).multipliedBy(0.5);
        make.centerX.equalTo(@0);
        make.top.equalTo(nameLabel.mas_bottom);
    }];
    [distanceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.bottom.equalTo(redView);
        make.height.equalTo(@20);
    }];
    
    return redView;
}

@end
